using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Shop_Manage_shop_product_category : Member, IRequiresSessionState
{
	protected LinkButton LinkProductunClassed;
	protected Repeater Repeater1;
	protected TextBox TxtClassName;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected TextBox TxtOrderBy;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected Button AddCategoryButton;
	protected Label LbError;
	protected HiddenField HiddenID;
	protected HiddenField HiddenorderID;
	protected RangeValidator RangeValidator1;
	private int ShopID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopID = base.user.ShopID;
		if (this.ShopID <= 0)
		{
			this.WriteErrMsg("友情提示", Language.GetMemberMsg("Common/NoShop", new string[0]), "../Member/Shop_OpenShop.aspx");
		}
		if (!base.IsPostBack)
		{
			ShopGroupBll shopGroupBll = new ShopGroupBll(this.conn);
			string groupPowerByShopID = shopGroupBll.GetGroupPowerByShopID(this.ShopID);
			if (!shopGroupBll.CheckGroupPower(groupPowerByShopID, "addclass"))
			{
				this.WriteErrMsg("", Language.Get("Shop/Class/NoAddClass"), "");
			}
			this.BindList();
		}
	}
	public void BindList()
	{
		this.Repeater1.DataSource = this.conn.GetDataSet("select * from HLShop_ProductLikeCategory where ShopID=" + this.ShopID + " order by orderby asc");
		this.Repeater1.DataBind();
	}
	protected void Button2_Click(object sender, EventArgs e)
	{
		int num = 0;
		this.LbError.Text = "";
		string text = this.TxtClassName.Text.ToString();
		Regex regex = new Regex("\\<\\/?[^\\<]*\\>");
		text = regex.Replace(text, "");
		char[] array = text.ToCharArray();
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i].ToString() != "")
			{
				num++;
			}
		}
		if (num > 50)
		{
			this.LbError.Text = "不能超过50个数字（不包括html标签在内）";
		}
		else
		{
			Shop_ProductLikeCategory shop_ProductLikeCategory = new Shop_ProductLikeCategory();
			string text2 = base.Server.HtmlEncode(this.TxtClassName.Text.Trim());
			int num2 = int.Parse(this.TxtOrderBy.Text);
			if (this.AddCategoryButton.Text == "添加")
			{
				if (this.conn.ExecuteCount(string.Concat(new object[]
				{
					"select count(*) from HLShop_ProductLikeCategory where orderby=",
					int.Parse(this.TxtOrderBy.Text),
					" and ShopID=",
					this.ShopID
				})) > 0)
				{
					this.LbError.Text = "该排序号已存在！";
					return;
				}
				bool flag = shop_ProductLikeCategory.IsSame(this.ShopID, num2, text2);
				if (flag)
				{
					this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('排序号和分类名不能重复!');</script>");
					return;
				}
			}
			else
			{
				bool flag2 = false;
				DataSet dataSet = this.conn.GetDataSet("select * from HLShop_ProductLikeCategory where ShopID=" + this.ShopID);
				for (int j = 0; j < dataSet.Tables[0].Rows.Count; j++)
				{
					if (int.Parse(dataSet.Tables[0].Rows[j]["orderby"].ToString()) == int.Parse(this.TxtOrderBy.Text) && int.Parse(dataSet.Tables[0].Rows[j]["orderby"].ToString()) != int.Parse(this.HiddenorderID.Value))
					{
						flag2 = true;
						break;
					}
				}
				if (flag2)
				{
					this.LbError.Text = "该排序号已存在！";
					return;
				}
			}
			ShopGroupBll shopGroupBll = new ShopGroupBll(this.conn);
			int powerByKey = shopGroupBll.GetPowerByKey<int>("MaxClass", this.ShopID);
			if (powerByKey > 0)
			{
				if (shop_ProductLikeCategory.CountByShopID(this.ShopID) >= powerByKey)
				{
					this.WriteErrMsg("", Language.GetMemberMsg("Category/MaxClass", new string[]
					{
						powerByKey.ToString()
					}), "");
				}
			}
			if (this.AddCategoryButton.Text == "添加")
			{
				if (shop_ProductLikeCategory.InsertProductLikeCategory(this.ShopID, text2, num2))
				{
					this.TxtClassName.Text = "";
					this.TxtOrderBy.Text = "";
					this.BindList();
				}
				else
				{
					this.WriteErrMsg("", Language.Get("Common/Fail", "0"), "");
				}
			}
			else
			{
				int num3 = this.conn.Execute(string.Concat(new object[]
				{
					"update HLShop_ProductLikeCategory set ShopProductClassName='",
					this.TxtClassName.Text,
					"',orderby=",
					int.Parse(this.TxtOrderBy.Text),
					" where ShopProductClassID=",
					int.Parse(this.HiddenID.Value)
				}));
				this.BindList();
				this.HiddenorderID.Value = this.TxtOrderBy.Text;
			}
		}
	}
	protected void LinkProductunClassed_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("~/Manage/Shop_ViewProductByShopProductClassID.aspx?ShopProductClassID=0");
	}
	public string Filterhtml(string Htmlstring)
	{
		Htmlstring = Regex.Replace(Htmlstring, "<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "<(.[^>]*)>", "", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "([\\r\\n])[\\s]+", "", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "-->", "", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "<!--.*", "", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(quot|#34);", "\"", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(amp|#38);", "&", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(lt|#60);", "<", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(gt|#62);", ">", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(iexcl|#161);", "¡", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(cent|#162);", "¢", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(pound|#163);", "£", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&(copy|#169);", "©", RegexOptions.IgnoreCase);
		Htmlstring = Regex.Replace(Htmlstring, "&#(\\d+);", "", RegexOptions.IgnoreCase);
		Htmlstring.Replace("<", "");
		Htmlstring.Replace(">", "");
		Htmlstring.Replace("\r\n", "");
		Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
		return Htmlstring;
	}
	protected void lbtEdit_Click(object sender, EventArgs e)
	{
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		Label label = repeaterItem.FindControl("ClassID") as Label;
		Label label2 = repeaterItem.FindControl("ClassName") as Label;
		Label label3 = repeaterItem.FindControl("LborderID") as Label;
		this.TxtClassName.Text = label2.Text;
		this.TxtOrderBy.Text = label3.Text;
		this.HiddenID.Value = label.Text;
		this.HiddenorderID.Value = label3.Text;
		this.AddCategoryButton.Text = "更新";
	}
	protected void lbtDel_Click(object sender, EventArgs e)
	{
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		Label label = repeaterItem.FindControl("ClassID") as Label;
		int num = this.conn.Execute("delete HLShop_ProductLikeCategory where ShopProductClassID=" + int.Parse(label.Text));
		this.BindList();
	}
}
